package org.ms.mconf.sdk;

import lombok.Getter;
import org.micro.URL;

/**
 * The Definition Constant
 *
 * @author lry
 */
@Getter
public enum Constants {

    /**
     * The subscribe executor corePoolSize
     */
    SUB_EXECUTOR_CORE_POOL_SIZE("subscribe.corePoolSize", 1),
    /**
     * The subscribe executor maximumPoolSize
     */
    SUB_EXECUTOR_MAXIMUM_POOL_SIZE("subscribe.maximumPoolSize", 20),
    /**
     * The subscribe executor keepAliveTime
     */
    SUB_EXECUTOR_KEEP_ALIVE_TIME("subscribe.keepAliveTime", 10000L),

    /**
     * The pull executor corePoolSize
     */
    PULL_EXECUTOR_CORE_POOL_SIZE("pull.corePoolSize", 1),
    /**
     * The pull executor initialDelay
     */
    PULL_EXECUTOR_INITIAL_DELAY("pull.initialDelay;", 0L),
    /**
     * The pull executor period
     */
    PULL_EXECUTOR_PERIOD("pull.period", 10000L),
    /**
     * The config data cache file path
     */
    CACHE_FILE("cache-file", System.getProperty("user.dir") + "/.mconf-cache.yaml"),
    /**
     * The config data center ndoe
     */
    NODE("node", "node0"),
    /**
     * The config group path
     */
    GROUP("group", "mconf");

    private final String name;
    private final String value;
    private long longValue;
    private int intValue;
    private boolean boolValue;

    public static String get(URL url, Constants c) {
        return url.getParameter(c.getName(), c.getValue());
    }

    public static long getLongValue(URL url, Constants c) {
        return url.getParameter(c.getName(), c.getLongValue());
    }

    public static int getIntValue(URL url, Constants c) {
        return url.getParameter(c.getName(), c.getIntValue());
    }

    public static boolean isBoolValue(URL url, Constants c) {
        return url.getParameter(c.getName(), c.isBoolValue());
    }

    Constants(String name, String value) {
        this.name = name;
        this.value = value;
    }

    Constants(String name, long longValue) {
        this.name = name;
        this.value = String.valueOf(longValue);
        this.longValue = longValue;
    }

    Constants(String name, int intValue) {
        this.name = name;
        this.value = String.valueOf(intValue);
        this.intValue = intValue;
    }

    Constants(String name, boolean boolValue) {
        this.name = name;
        this.value = String.valueOf(boolValue);
        this.boolValue = boolValue;
    }

    public static final String MATCH_ALL = "*";
    public static final String DELIMITER = ":";
    public static final String DOT = ".";
    public static final String ACTION_SEQ = "@";
    public static final String SEQ = ",";
    private static final String MATCH = "%s";

    public static final String DATA_KEY = "data";
    private static final String CHANGELOG_KEY = "changelog";
    public static final String CHANNEL_KEY = "channel";


    public static final String ENV_KEY = "env";
    public static final String ACV_KEY = "acv";

    public static final String APPLICATION_KEY = "application";
    public static final String CONFIG_KEY = "config";
    public static final String VERSION_KEY = "version";

    public static final String MAX_IDLE_KEY = "maxIdle";
    public static final String MIN_IDLE_KEY = "minIdle";
    public static final String MAX_TOTAL_KEY = "maxTotal";
    public static final String TIMEOUT_KEY = "timeout";
    public static final String PASSWORD_KEY = "password";
    public static final String DATABASE_KEY = "database";

    /**
     * %s:changelog:%s:%s:%s:%s
     */
    public static final String CHANGELOG_TEMPLATE_KEY = String.join(DELIMITER, MATCH, CHANGELOG_KEY, MATCH, MATCH, MATCH, MATCH);

}
